package com.fenghongzhang.day010;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import master.flame.danmaku.controller.DrawHandler;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.danmaku.model.IDanmakus;
import master.flame.danmaku.danmaku.model.android.DanmakuContext;
import master.flame.danmaku.danmaku.model.android.Danmakus;
import master.flame.danmaku.danmaku.parser.BaseDanmakuParser;
import master.flame.danmaku.ui.widget.DanmakuView;

public class MainActivity extends AppCompatActivity {
    private Button btn;
    private DanmakuView danmaku;
    private DanmakuContext danmakuContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btn = (Button) findViewById(R.id.btn);
        danmaku = (DanmakuView) findViewById(R.id.danmaku);


         danmakuContext = DanmakuContext.create();

         danmaku.prepare(new BaseDanmakuParser() {
             @Override
             protected IDanmakus parse() {
                 return new Danmakus();
             }
         },danmakuContext);


         danmaku.setCallback(new DrawHandler.Callback() {
             @Override
             public void prepared() {
                 danmaku.start();
             }

             @Override
             public void updateTimer(DanmakuTimer timer) {

             }

             @Override
             public void danmakuShown(BaseDanmaku danmaku) {

             }

             @Override
             public void drawingFinished() {

             }
         });
    }

    public void send(View view) {

        BaseDanmaku baseDanmaku = danmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
        baseDanmaku.text = "这是一条弹幕"+System.currentTimeMillis() ;
        baseDanmaku.padding = 5;
        baseDanmaku.priority = 1;  // 可能会被各种过滤器过滤并隐藏显示
        baseDanmaku.isLive = true;
        baseDanmaku.textSize = 25f;
        baseDanmaku.setTime(danmaku.getCurrentTime()+1200);
        baseDanmaku.textColor = Color.RED;
        baseDanmaku.textShadowColor = Color.WHITE;
        baseDanmaku.underlineColor = Color.GREEN;
        baseDanmaku.borderColor = Color.GREEN;
        danmaku.addDanmaku(baseDanmaku);

    }
}
